package com.ruoyi.merchant.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.merchant.domain.ImsExpressInfo;
import com.ruoyi.merchant.service.IImsExpressInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 快递地址Controller
 * 
 * @author ruoyi
 * @date 2024-07-10
 */
@RestController
@RequestMapping("/expressinfo/expinfo")
public class ImsExpressInfoController extends BaseController
{
    @Autowired
    private IImsExpressInfoService imsExpressInfoService;

    /**
     * 查询快递地址列表
     */
    //@PreAuthorize("@ss.hasPermi('expressinfo:expinfo:list')")
    @GetMapping("/list")
    @Anonymous
    public TableDataInfo list(ImsExpressInfo imsExpressInfo)
    {
        startPage();
        List<ImsExpressInfo> list = imsExpressInfoService.selectImsExpressInfoList(imsExpressInfo);
        return getDataTable(list);
    }

    /**
     * 导出快递地址列表
     */
    @PreAuthorize("@ss.hasPermi('expressinfo:expinfo:export')")
    @Log(title = "快递地址", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ImsExpressInfo imsExpressInfo)
    {
        List<ImsExpressInfo> list = imsExpressInfoService.selectImsExpressInfoList(imsExpressInfo);
        ExcelUtil<ImsExpressInfo> util = new ExcelUtil<ImsExpressInfo>(ImsExpressInfo.class);
        util.exportExcel(response, list, "快递地址数据");
    }

    /**
     * 获取快递地址详细信息
     */
    //@PreAuthorize("@ss.hasPermi('expressinfo:expinfo:query')")
    @GetMapping(value = "/{id}")
    @Anonymous
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(imsExpressInfoService.selectImsExpressInfoById(id));
    }

    /**
     * 新增快递地址
     */
    //@PreAuthorize("@ss.hasPermi('expressinfo:expinfo:add')")
    @Log(title = "快递地址", businessType = BusinessType.INSERT)
    @PostMapping
    @Anonymous
    public AjaxResult add(@RequestBody ImsExpressInfo imsExpressInfo)
    {
        AjaxResult ajax=AjaxResult.success();
        imsExpressInfoService.insertImsExpressInfo(imsExpressInfo);
        ajax.put("expressId",imsExpressInfo.getId());
        return  ajax;
    }

    /**
     * 修改快递地址
     */
    //@PreAuthorize("@ss.hasPermi('expressinfo:expinfo:edit')")
    @Log(title = "快递地址", businessType = BusinessType.UPDATE)
    @PutMapping
    @Anonymous
    public AjaxResult edit(@RequestBody ImsExpressInfo imsExpressInfo)
    {
        return toAjax(imsExpressInfoService.updateImsExpressInfo(imsExpressInfo));
    }

    /**
     * 删除快递地址
     */
    //@PreAuthorize("@ss.hasPermi('expressinfo:expinfo:remove')")
    @Log(title = "快递地址", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @Anonymous
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(imsExpressInfoService.deleteImsExpressInfoByIds(ids));
    }
}
